package itfuge.web;
import itfuge.service.BookService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.lang.reflect.Field;
import java.util.Map;

public class App {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        //创建Ioc容器对象，加载spring核心配置文件
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        //从IOC容器中获取Bean对象(BookService对象)
        BookService bookService = (BookService) ctx.getBean("bookService");
        //调用Bean对象(BookService)的方法
        bookService.save();

        System.out.println("---------------");
        Field singletonObjects = DefaultSingletonBeanRegistry.class.getDeclaredField("singletonObjects");
        System.out.println(singletonObjects);
        singletonObjects.setAccessible(true);

        Map<String,Object> map =(Map<String, Object>) singletonObjects.get(ctx);
        System.out.println(map);
    }
}
